<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/29 0029
 * Time: 9:59
 */
namespace App\FreeBird\Controllers\Admin;
use App\Base\Controllers\Controller;


use App\FreeBird\Contracts\InfoComplaintInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;

/**
 *
 * Class StoreUserController
 * @package App\FreeBird\Controllers\Admin
 */
class ComplaintController extends Controller
{

    /**
     * 用户操作
     * @return InfoComplaintInterface
     */
    public function getInfoComplaintInterface(){
        return app()->make(InfoComplaintInterface::class);
    }


    public function index(Request $request){

        if($request->getMethod()=='POST'){

            $where=function($query) use ($request){
                $username=$request->input("username");
                if(!empty($title)){
                    $query->where("username","like",'%'.$username.'%');
                }
                $apply_status=$request->input("apply_status","");
                if($apply_status!=''){
                    $query->where("apply_status",$apply_status);
                }
                $query->where("freebird_info_complaint.status",1);
            };
            return  $this->getInfoComplaintInterface()->getListWith($where);
        }
        return view("freebird.complaint.index");
    }

    /**
     * 审核通过
     * @param Request $request
     */
    public function apply(Request $request){
       $orderSn=$request->input("id");
        if($request->getMethod()=='POST'){
            $validator = Validator::make($request->all(), [
                'apply_msg' => 'required',
                'bili' => 'required',
                'order_sn' => 'required',
            ], ["apply_msg.required" => '理由',"bili.required" => '比率',"order_sn.required" => '订单号']);
            if ($validator->fails()) {
                $this->throwValidatorException($validator);
            }
            return $this->getInfoComplaintInterface()->sendBiliUserBalance($request->all());
        }
        $info=$this->getInfoComplaintInterface()->getInfoWithOder($orderSn);

        return view("freebird.complaint.apply")->with("order_sn",$orderSn)->with("info",$info);
    }

    public function show(Request $request){

         $orderSn=$request->input("id");
         $info=$this->getInfoComplaintInterface()->getShowByOrderSn($orderSn);
          return view("freebird.complaint.show")->with("info",$info);
    }



}